import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
//引入测试数据
import { loginUsers, listCourse } from './data/user';
import { ExamPaper} from './data/exam';
import { listResource,sectionDataById,partData,videoInfo} from './data/resource';
import { listThesis} from './data/thesis'
import {listThesisLayout} from './data/thesisLayout'
import {listTransaction} from  './data/transactionList'
import {listSection} from './data/sectionList'
import {listSectionTestPaper} from './data/listSectionTestPaper'


let _listCourse = listCourse
let _listThesis = listThesis
let _listThesisLayout = listThesisLayout
let _listTransaction= listTransaction
let _listSection = listSection
let _listSectionTestPaper = listSectionTestPaper
let _examPaper = ExamPaper;
let _listResource = listResource;
let _sectionDataById = sectionDataById;
let _partData = partData, _videoInfo = videoInfo;

export default {

  mockTest() {
    let mock = new MockAdapter(axios) ;
    //模拟学生论文列表
  mock.onPost('/api/student/thesis/showThesisByPage').reply(200,{status:200,message:'', resData: _listThesis}) ;
  //模拟学生论文规范列表
  mock.onPost('/api/student/thesisLayout/queryThesisLayout').reply(200,{status:200,message:'',resData: {
    pageSize:10,
    total:200,
    list:[{
      thesisLayoutId:1,
      thesisLayoutName:"java论文规范",
      thesisLayoutUpdate:1498665600000,
      thesisLayoutContent:'https://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=https%3A%2F%2Ftimgsa.baidu.com%2Ftimg%3Fimage%26quality%3D80%26size%3Db9999_10000%26sec%3D1517289161070%26di%3D0d3049b68bc7825e621b42a0326526a9%26imgtype%3D0%26src%3Dhttp%253A%252F%252Fimg15.3lian.com%252F2015%252Ff1%252F61%252Fd%252F2.jpg&thumburl=https%3A%2F%2Fss2.bdstatic.com%2F70cFvnSh_Q1YnxGkpoWK1HF6hhy%2Fit%2Fu%3D1994069236%2C309463222%26fm%3D27%26gp%3D0.jpg',
       zip: 200333
  },{
    thesisLayoutId:1,
    thesisLayoutName:"java论文规范",
    thesisLayoutUpdate:1498665600000,
    thesisLayoutContent:'https://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=https%3A%2F%2Ftimgsa.baidu.com%2Ftimg%3Fimage%26quality%3D80%26size%3Db9999_10000%26sec%3D1517289161070%26di%3D0d3049b68bc7825e621b42a0326526a9%26imgtype%3D0%26src%3Dhttp%253A%252F%252Fimg15.3lian.com%252F2015%252Ff1%252F61%252Fd%252F2.jpg&thumburl=https%3A%2F%2Fss2.bdstatic.com%2F70cFvnSh_Q1YnxGkpoWK1HF6hhy%2Fit%2Fu%3D1994069236%2C309463222%26fm%3D27%26gp%3D0.jpg',
     zip: 200333
  },{
    thesisLayoutId:1,
    thesisLayoutName:"java论文规范",
    thesisLayoutUpdate:1498665600000,
    thesisLayoutContent:'https://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=https%3A%2F%2Ftimgsa.baidu.com%2Ftimg%3Fimage%26quality%3D80%26size%3Db9999_10000%26sec%3D1517289161070%26di%3D0d3049b68bc7825e621b42a0326526a9%26imgtype%3D0%26src%3Dhttp%253A%252F%252Fimg15.3lian.com%252F2015%252Ff1%252F61%252Fd%252F2.jpg&thumburl=https%3A%2F%2Fss2.bdstatic.com%2F70cFvnSh_Q1YnxGkpoWK1HF6hhy%2Fit%2Fu%3D1994069236%2C309463222%26fm%3D27%26gp%3D0.jpg',
     zip: 200333
  },{
    thesisLayoutId:1,
    thesisLayoutName:"java论文规范",
    thesisLayoutUpdate:1498665600000,
     zip: 200333
  },{
    thesisLayoutId:1,
    thesisLayoutName:"java论文规范",
    thesisLayoutUpdate:1498665600000,
     zip: 200333
  }
  ]
  }});
  mock.onPost("/api/student/updateStudentInfo").reply(200,{status:200,message:'成功',resData:  null})
  mock.onPost("/api/student/checkStuPass").reply(200,{status:200,message:'成功',resData:  null})
  mock.onPost('/api/student/thesis/add').reply(200,{status:200,message:'上传成功',resData:  null})
  //模拟学生异动申请列表
  mock.onPost('/api/student/transaction/queryTransaction').reply(200,{status:200,message:'',resData:  _listTransaction});
  //模拟学生异动申请填写
  mock.onPost('/api/student/transaction/save').reply(200,{status:200,message:''});
  //章节测试列表
  mock.onPost('/api/student/listSectionTest').reply(200,{status:200,message:'',resData: _listSection});
  //章节测试题目列表
  mock.onPost('/api/student/listSectionTestPaper').reply(200,{status:200,message:'',resData:_listSectionTestPaper});
  mock.onPost('/api/student/saveSectionTest').reply(200, {status:200, message:'提交成功'});

    mock.onPost('/api/student/listCourse').reply(200,{status:200, message:'', resData: _listCourse}) ;

    //模拟学生登陆
    mock.onPost('/api/student/login').reply(200,{status:200, message:'登陆成功', resData: {user:1111,password:123}})
    mock.onPost('sad/api/student/login').reply(config =>{

      /*
      some() 方法用于检测数组中的元素是否满足指定条件（函数提供）。
      some() 方法会依次执行数组的每个元素：
      如果有一个元素满足条件，则表达式返回true , 剩余的元素不会再执行检测。
      如果没有满足条件的元素，则返回false。
      */
      /*
      JSON对象有两个方法：stringify()和parse()。在最简单的情况下，
      这两个方法分别用于把JavaScript对象序列化为JSON字符串和把JSON字符串解析为原生JavaScript。
      */

      let {user, password, rememberMe } = JSON.parse(config.data)
      return new Promise((resolve, reject) => { //异步操作，成功resolve继续执行
        let resData = null ;
        setTimeout(() => {// 短暂延迟后
          let hasUser = loginUsers.some(u => {
            if (u.user === user && u.password === password) {
              console.log(u);
              resData = JSON.parse(JSON.stringify(u));
              resData.password = '';
              resData.rememberMe = rememberMe;
              return true ;
            }
          });
          if (hasUser){/* 异步操作成功 */
            console.log("resData:" + resData);
            resolve([200,{status:200,message:'登陆成功',resData}]);
          } else {
            reject(500,{status:505,message:'账号或密码错误'});
          }
        },200)
      });

      // promise.then(function(value) {
      //  // success
      // }, function(value) {
      //  // failure
      // });
    });

    mock.onPost('/api/student/listExamOrder').reply(200,{status:200,message:'',resData:
    {
      total:4,
      pageSize:10,

      list:[
        {courseId:1,

        isOrder: false,
        isPassOrder: false,
        examForm: '网上考试',
        examTime: 1430755200000,
        course: {
          courseName: '语文'
        }

      },
      {courseId:2,
        course: {
          courseName: '语文'
        },
      isOrder: false,
      isPassOrder: false,
      examForm: '现场考试',
      examTime: '2018-12-20 8:00-10:00'

    },
    {courseId:3,
      course: {
        courseName: '政治'
      },
    isOrder: false,
    isPassOrder: false,
    examForm: '网上考试',
    examTime: '2018-12-20 8:00-10:00'

  },
  {courseId:4,
    course: {
      courseName: '英文'
    },
  isOrder: false,
  isPassOrder: false,
  examForm: '现场考试',
  examTime: '2018-12-20 8:00-10:00'
},
]
}
});
mock.onPost('/api/student/listEducation').reply(200,{status:200,message:'',resData:
{
  total:20,
  pageSize:10,

  list:[
    {
    educationPlanId: 1,
    educationGrade: '2013级',
    courseName: '大型数据库',
    courseType: '必修',
    studyScore:5,
    studyTerm:5,
    major:{
      majorName: "计算机应用与技术",
    }
  },
  {
  educationPlanId:5,
  educationGrade: '2013级',
  courseName: '大型数据库',
  courseType: '必修',
  studyScore:5,
  studyTerm:5,
  major:{
    majorName: "网络工程",
  }
},
{
educationPlanId:3,
educationGrade: '2013级',
courseName: '大型数据库',
courseType: '必修',
studyScore:5,
studyTerm:5,
major:{
  majorName: "计算机应用与技术",
}
},
{
educationPlanId: 2,
educationGrade: '2013级',
courseName: '大型数据库',
courseType: '必修',
studyScore:5,
studyTerm:5,
major:{
  majorName: "计算机应用与技术嵌入式",
}
}
]
}
});
mock.onPost('/api/student/saveExamOrder').reply(200,{status:200,message:'预约成功'});
mock.onPost('/api/student/listScore').reply(200,{status:200,message:'',resData:{
  total:20,
  pageSize:10,
  list:[
    {
      course:{
        courseName:'数字逻辑'
      }  ,
      scoreDelete:1,
      scoreOntime:10,
      scoreCredit:89
  },
  {
    course:{
      courseName:'数字逻辑'
    }  ,
    scoreDelete:1,
    scoreOntime:10,
    scoreCredit:89
},
]
}});
mock.onPost('/api/student/studentSelfInfo').reply(200,{status:200,message:'',resData:
  {
    studentId:1,
    studentName:'顾军伟',
    studentSex:'男',
    studentPhoto:'照片',
    studentBirth:1498665600000,
    studentNation:'汉',
    studentIdCard:'410521199505068065',
    studentPhoto:'@/assets/logo.jpg',
    studentEducation:'本科',
    studentEmail:'1202546@qq.com',
    studentAddress:'河南驻马店',
    studentGraduate:'河南理工',
    studentPhone:'15365981526',
    major:{
      majorName:'计算机科学与技术'
    }

}});
mock.onPost('/api/student/thesis/download').reply(200,{status:200,message:'修改成功',resData: 'https://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=https%3A%2F%2Ftimgsa.baidu.com%2Ftimg%3Fimage%26quality%3D80%26size%3Db9999_10000%26sec%3D1517289161070%26di%3D0d3049b68bc7825e621b42a0326526a9%26imgtype%3D0%26src%3Dhttp%253A%252F%252Fimg15.3lian.com%252F2015%252Ff1%252F61%252Fd%252F2.jpg&thumburl=https%3A%2F%2Fss2.bdstatic.com%2F70cFvnSh_Q1YnxGkpoWK1HF6hhy%2Fit%2Fu%3D1994069236%2C309463222%26fm%3D27%26gp%3D0.jpg'}) ;
mock.onPost('/api/admin/StudentmanageUp').reply(200,{status:200,message:'修改成功'});
mock.onPost('/api/student/listExamPaper').reply(200,{status:200,message:'',resData:_examPaper});
mock.onPost('/api/student/listResource').reply(200,{status:200,message:'',resData:_listResource});
mock.onPost('/api/student/downResource').reply(200,{status:200,message:'下载完成'});
mock.onPost('/api/student/getCourseById').reply(200,{status:200,message:'',resData:_sectionDataById});
mock.onPost('/api/student/getPartSectionBySectionId').reply(200,{status:200,message:'',resData:_partData});
mock.onPost('/api/student/downloadViedo').reply(200,{status:200,message:'',resData:_videoInfo});
mock.onPost('/api/student/logout').reply(200,{status:200,message:'退出成功'})
//李世阳
mock.onPost('/api/student/listNotice').reply(200,{status:200,message:'',resData:{
     total:4,
     pageSize:2,
     list:[
       {
         noticeId:'10086',
         noticeName:'寒假日期公告',
         noticeDate:1498665600000
       },
       {
         noticeId:'10087',
         noticeName:'暑假日期公告',
         noticeDate:'1991-06-15'
       },
       {
         noticeId:'10088',
         noticeName:'寒假日期公告',
         noticeDate:1498665600000
       },
       {
         noticeId:'10088',
         noticeName:'寒假日期公告',
         noticeDate:'1991-02-15'
       }
     ]
   }});
   mock.onPost('/api/student/listTeacherByStuId').reply(200,{status:200,message:'',resData:{
     pageSize:1,
     total:100,
       list:[{
         teacherId:'1',
         teacherRealname:'王者',
         teacherSchool:'航院',
         teacherDegree:'中科院士',
         notes:'备注'
       },
       {
         teacherId:'1',
         teacherRealname:'王者',
         teacherSchool:'航院',
         teacherDegree:'中科院士',
         notes:'备注'
       },
       {
         teacherId:'1',
         teacherRealname:'王者',
         teacherSchool:'航院',
         teacherDegree:'中科院士',
         notes:'备注'
       }
     ]

   }});
   mock.onPost('/api/student/getStudentInfo').reply(200,{status:200,message:'',resData:{

    studentId:'20170001',
    studentName:'王晓伟',
    studentSex:'男',
    exams:[{
      course:{
        courseName:'数学',

      },
        examTime:1498665600000,
        examPlace:'郑州市XX区XX路XX校区6号楼322室'
    },
    {
      course:{
        courseName:'语文',

      },
        examTime:1498665600000,
        examPlace:'郑州市XX区XX路XX校区6号楼322室'
    }
]

}});
   mock.onPost('/api/student/getNoticeById').reply(200,{status:200,message:'',resData:{

      noticeInf:'李仕gyuhyufgtygvyuvgyuvguyvguhgugu8gvuvuygvuhbuh8ihiiihinjijnininimkl大叔大婶大所adad啊大叔啊按时大 按时大大的啊ad啊的jhnfy'
    }});
    mock.onPost('/api/student/saveTeacherEvaluate').reply(200,{status:500,message:'评价失败'});
}
}
